package Work;

import java.io.Serializable;
import java.util.Objects;

// 支持序列化，用于网络传输
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    private String username;   // 账号
    private String password;   // 密码（实际项目建议加密存储）
    private String role;       // 角色：ADMIN（管理员）/ USER（普通用户）

    public User(String username, String password, String role) {
        this.username = username;
        this.password = password;
        this.role = role;
    }

    // Getters & Setters
    public String getUsername() { return username; }
    public String getPassword() { return password; }
    public String getRole() { return role; }

    // 管理员权限判断
    public boolean isAdmin() {
        return "ADMIN".equalsIgnoreCase(role);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(username, user.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username);
    }
}